/*
 * Copyright (c) 2020 pig4cloud Authors. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.love.cloud.admin.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.love.cloud.admin.api.entity.SysAuthLog;
import com.love.cloud.admin.api.vo.SysAuthLogVo;
import com.love.cloud.admin.mapper.AuthLogMapper;
import com.love.cloud.admin.service.AuthLogService;
import org.springframework.stereotype.Service;


@Service
public class AuthLogServiceImpl extends ServiceImpl<AuthLogMapper, SysAuthLog> implements AuthLogService {

	@Override
	public Page getLogByPage(Page page, SysAuthLogVo sysAuthLogVo) {
		LambdaQueryWrapper<SysAuthLog> wrapper = Wrappers.lambdaQuery();
		if (StrUtil.isNotBlank(sysAuthLogVo.getType())) {
			wrapper.eq(SysAuthLog::getType, sysAuthLogVo.getType());
		}
		if (StrUtil.isNotBlank(sysAuthLogVo.getCreateName())) {
			wrapper.eq(SysAuthLog::getCreateName, sysAuthLogVo.getCreateName());
		}

		if (StrUtil.isNotBlank(sysAuthLogVo.getStartTime() )&& StrUtil.isNotBlank(sysAuthLogVo.getEndTime())) {
			wrapper.ge(SysAuthLog::getCreateTime, sysAuthLogVo.getStartTime()+" 00:00:00").le(SysAuthLog::getCreateTime,
					sysAuthLogVo.getEndTime()+" 23:59:59");
		}
		wrapper.orderByDesc(SysAuthLog::getCreateTime);
		return baseMapper.selectPage(page, wrapper);
	}

}
